#!/bin/bash

# simple script to set up a test environment for metering.
# two namespaces connected by a virtual switch, pointing at a local OF
# controller.

sudo ip netns add left
sudo ip netns add right
sudo ip link add veth01 type veth peer name veth10
sudo ip link set veth01 netns left                                                                                                                                                             
sudo ip link set veth10 up

sudo ip link add veth02 type veth peer name veth20                                                                                                                                             
sudo ip link set veth02 netns right                                                                                                                                                            
sudo ip link set veth20 up                                                                                                                                                                     

sudo ovs-vsctl add-br vswitch
sudo ovs-vsctl set-fail-mode vswitch secure                                                                                                                                                    

sudo ovs-vsctl add-port vswitch veth10
sudo ovs-vsctl add-port vswitch veth20

sudo ip netns exec left ifconfig veth01 192.168.201.1 up                                                                                                                                       
sudo ip netns exec left route add -net 192.168.202.0/24 gw 192.168.201.1

sudo ip netns exec right ifconfig veth02 192.168.202.1 up
sudo ip netns exec right route add -net 192.168.201.0/24 gw 192.168.202.1

# set the controller to a default localhost controller
sudo ovs-vsctl set-controller vswitch tcp:127.0.0.1:6633

# set the vswitch to use openflow 1.0 and 1.4
# we need 1.0 apparently for ovs-ofctl to work, and flow_stats
# doesn't work in 1.5
sudo ovs-vsctl set bridge vswitch protocols=OpenFlow10,OpenFlow14

